<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%--表格js引入 [start] --%>
<!-- Include all compiled plugins (below), or include individual files as needed -->

<script
	src="${pageContext.request.contextPath}/wxflow/res1/assets/js/vendor/chosen/chosen.jquery.min.js"></script>

<%--表格js引入 [end] --%>
<script>
var modal_id = "";//弹框需提交的ID
	//ajax获取表格数据---[start]
	function jqAjax_i1510() {
		var _this = this;
		this.pageNo;
		this.pageSize;
		this.totalCount;
		this.pageUrl;
		this.sessionOutUrl;
		this.addUrl;
		this.modifyUrl;
		this.deleteUrl;
		this.parameter = new Object();
		this.init = function(init_parameter) {
			if (typeof init_parameter['pageNo'] != "undefined") {
				_this.pageNo = init_parameter['pageNo'];
			}
			if (typeof init_parameter['pageSize'] != "undefined") {
				_this.pageSize = init_parameter['pageSize'];
			}
			if (typeof init_parameter['totalCount'] != "undefined") {
				_this.totalCount = init_parameter['totalCount'];
			}
			if (typeof init_parameter['pageUrl'] != "undefined") {
				_this.pageUrl = init_parameter['pageUrl'];
			}
			if (typeof init_parameter['sessionOutUrl'] != "undefined") {
				_this.sessionOutUrl = init_parameter['sessionOutUrl'];
			}
			//绑定
			$("#pagePrev").bind("click",_this.fn_turnPage);
			$("#pageNext").bind("click",_this.fn_turnPage);
			$("#pageGo").bind("click",_this.fn_turnPage);
			$("#fn_add").bind("click",_this.fn_add);
			$("#fn_modify").bind("click",_this.fn_modify);
			$("#fn_delete").bind("click",_this.fn_delete);
		}
		//查询
		this.fn_turnPage = function() {
			_this.parameter = parameter;
			var clickId = $(this).attr("id");
			var mode = $("#"+clickId).data("mode");
			if(typeof mode != "undefined"){
				if(mode == "prev"){
					var pageNo = $("#pageNo").val();
					if(pageNo == null || pageNo < 2){
						pageNo = _this.pageNo;
					}else{
						pageNo = Number(pageNo) - 1;
					}
					_this.parameter['pageNo'] = pageNo;
					var pageSize = $("#pageSize").val();
					if(pageSize == null || pageSize == "" ){
						pageSize = _this.pageSize;
					}
					_this.parameter['pageSize'] = pageSize;
					
				}else if(mode == "next"){
					var pageNo = $("#pageNo").val();
					if(pageNo == null || pageNo == ""){
						pageNo = _this.pageNo;
					}else{
						pageNo = Number(pageNo) + 1;
					}
					_this.parameter['pageNo'] = pageNo;
					var pageSize = $("#pageSize").val();
					if(pageSize == null || pageSize == ""){
						pageSize = _this.pageSize;
					}
					_this.parameter['pageSize'] = pageSize;
					
				}else if(mode == "go"){
					var pageNo = $("#pageNo").val();
					if(pageNo == null || pageNo == ""){
						pageNo = _this.pageNo;
					}else{
						pageNo = Number(pageNo);
					}
					_this.parameter['pageNo'] = pageNo;
					var pageSize = $("#pageSize").val();
					if(pageSize == null || pageSize == ""){
						pageSize = _this.pageSize;
					}
					_this.parameter['pageSize'] = pageSize;
				}
			}
			
			
			$
					.ajax({
						url : _this.pageUrl,
						async : true,
						dataType : 'json',
						type : 'GET',
						data : _this.parameter,
						success : function(rtn, textStatus) {
							//业务控制
							var dataStr = "";

							$.each(rtn.data.listData, function(i, item) {
								
								dataStr = dataStr + "<tr>";
								dataStr = dataStr + "	<td>";
								
								dataStr = dataStr + "<div class='checkbox check-transparent'>";
								dataStr = dataStr + "<input type='checkbox' value='"+item.docId+"' name='chck' id='chck"+i+"'>";
								dataStr = dataStr + "<label for='chck"+i+"'></label></div>";
								
								dataStr = dataStr + "	</td>";
								
								dataStr = dataStr + "	<td>";
								dataStr = dataStr + "		"+item.fdWxNickName;
								dataStr = dataStr + "	</td>";
								
								dataStr = dataStr + "	<td>";
								dataStr = dataStr + "		"+item.fdWxOpenId;
								dataStr = dataStr + "	</td>";
								
								dataStr = dataStr + "	<td>";
								dataStr = dataStr + "		"+item.fdWxHeadImgUrl;
								dataStr = dataStr + "	</td>";
								
								dataStr = dataStr + "</tr>";
									
							
								
							}); 
							$("#pageShow").html(dataStr);
				
							//分页
							var totalCount = rtn.data.totalCount;
							var pageNo = rtn.data.pageNo;
							var pageSize = rtn.data.pageSize;
							$("#totalCount").html(+totalCount);
							$("#pageNo").val(pageNo);
							$("#pageSize").val(pageSize);
							
						},
						error : function(jqXHR, textStatus, errorThrown) {
							var sessionstatus = jqXHRgetResponseHeader("sessionstatus");
							if (sessionstatus == "timeout") {
								alert("[timeout]您登陆已经超时，请重新登陆!");
								var req_address = _this.sessionOutUrl;
								window.location.href = req_address;
							}
						}

					});
		}
		//增加
		this.fn_add = function() {
			modal_id = "";
			//清空弹框数据
			$("#fdWxNickName").val("");
			$("#fdWxOpenId").val("");
			$("#fdWxHeadImgUrl").val("");
			
			$("#voteModal").modal("show");
		}
		//修改
		this.fn_modify = function() {
			//checkbox选中 只取一个
			var chcked = $('input:checkbox[name=chck]:checked').val();
			if(typeof chcked == "undefined"){
				alert("请选中一条纪录!");
			}else{
				fn_getModal(chcked);
			}
			
		}
		//删除
		this.fn_delete = function() {
			//checkbox选中
			var chcked = "";
		      $('input:checkbox[name=chck]:checked').each(function(i){
		       if(0==i){
		    	   chcked = $(this).val();
		       }else{
		    	   chcked += (","+$(this).val());
		       }
		      });
	       if(chcked == ""){
				alert("请至少选中一条纪录!");
			}else{
				alert(chcked);
			}
			
		}
		
	}

	var parameter = new Object();
	parameter['menu'] = "show";
	
	var jqAjax = new jqAjax_i1510();
	jqAjax
			.init({
				"pageNo" : "1",
				"pageSize" : "10",
				"totalCount" : "0",
				"pageUrl" : "${pageContext.request.contextPath}/admin/wxflowUser/list.do",
				"sessionOutUrl" : "${pageContext.request.contextPath}/wxflow/login.jsp",
				"addUrl" : "${pageContext.request.contextPath}/wxflow/login.jsp",
				"modifyUrl" : "${pageContext.request.contextPath}/wxflow/login.jsp",
				"deleteUrl" : "${pageContext.request.contextPath}/wxflowUser/delete.do",
				"parameter":parameter
			});
		
	//ajax获取表格数据---[end]
	
	//保存填写内容
	function fn_save(obj) {
		var data = new Object();
		data['docId'] = modal_id;
		data['fdWxNickName'] = $("#fdWxNickName").val();
		data['fdWxOpenId'] = $("#fdWxOpenId").val();
		data['fdWxHeadImgUrl'] = $("#fdWxHeadImgUrl").val();

		
		$
				.ajax({
					url : "${pageContext.request.contextPath}/admin/wxflowUser/save.do",
					async : true,
					dataType : 'json',
					type : 'POST',
					data : data,
					success : function(rtn, textStatus) {
						if (rtn.result == "success") {
							//界面控制
							
							//回写生成的docId
							modal_id = "";
						} else {

							alert(rtn.message);
						}
					},
					error : function(jqXHR, textStatus, errorThrown) {
						var sessionstatus = jqXHR
								.getResponseHeader("sessionstatus");
						if (sessionstatus == "timeout") {
							alert("[timeout]您登陆已经超时，请重新登陆!");
							var req_address = "${pageContext.request.contextPath}/wxflow/login.jsp";
							window.location.href = req_address;
						} else {
							alert("网络连接失败，请重试!");
						}
					}

				});

		$("#voteModal").modal("hide");
	}
	//获取填写内容
	function fn_getModal(docId) {
		var data = new Object();

		modal_id = docId;
		data['docId'] = modal_id;

		//清空弹框数据
		$("#fdWxNickName").val("");
		$("#fdWxOpenId").val("");
		$("#fdWxHeadImgUrl").val("");
		
		$
				.ajax({
					url : "${pageContext.request.contextPath}/admin/wxflowUser/view.do",
					async : true,
					dataType : 'json',
					type : 'GET',
					data : data,
					success : function(rtn, textStatus) {
						if (rtn.result == "success") {
							$("#fdWxNickName").val(rtn.data.fdWxNickName);
							$("#fdWxOpenId").val(rtn.data.fdWxOpenId);
							$("#fdWxHeadImgUrl").val(rtn.data.fdWxHeadImgUrl);

						} else {

							alert(data.message);
						}
					},
					error : function(jqXHR, textStatus, errorThrown) {
						var sessionstatus = jqXHR
								.getResponseHeader("sessionstatus");
						if (sessionstatus == "timeout") {
							alert("[timeout]您登陆已经超时，请重新登陆!");
							var req_address = "${pageContext.request.contextPath}/wxflow/login.jsp";
							window.location.href = req_address;
						} else {
							alert("网络连接失败，请重试!");
						}
					}

				});

		$("#voteModal").modal("show");
	}
	$(function() {

		//check all checkboxes
		$('table thead input[type="checkbox"]').change(
				function() {
					$(this).parents('table').find(
							'tbody input[type="checkbox"]').prop('checked',
							$(this).prop('checked'));
				});

		// sortable table
		$('.table.table-sortable th.sortable').click(
				function() {
					var o = $(this).hasClass('sort-asc') ? 'sort-desc'
							: 'sort-asc';
					$(this).parents('table').find('th.sortable').removeClass(
							'sort-asc').removeClass('sort-desc');
					$(this).addClass(o);
				});

		//chosen select input
		$(".chosen-select").chosen({
			disable_search_threshold : 10
		});

	})
</script>